<h1 class="page-header">
    <small>修改管理员信息</small>
</h1>
<hr/>
<div class="panel panel-inverse" data-sortable-id="form-stuff-1">
    <div class="panel-heading">
        <h4 class="panel-title">管理员信息</h4>
    </div>
    <div class="panel-body">
        <form class="form-horizontal" id="accountForm" name="accountForm" action="" method="post">
            <div class="form-group">
                <label class="col-md-3 control-label">用户名</label>
                <div class="col-md-9">
                    <input type="text" class="form-control" placeholder="用户名" disabled="" value="${account.accountName}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">编号</label>
                <div class="col-md-9">
                    <input type="text" class="form-control" placeholder="编号" disabled="" value="${account.accountKey}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">员工ID</label>
                <div class="col-md-9">
                    <input type="text" class="form-control" id="staffId" name="staffId" placeholder="员工ID" value="${account.staffId}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">真实姓名</label>
                <div class="col-md-9">
                    <input type="text" id="realName" class="form-control" name="realName" placeholder="真实姓名 最长20位"
                           maxlength="20"  value="${account.realName}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">账户密码</label>

                <div class="col-md-9">
                    <input type="password" id="password" class="form-control" name="password"
                           placeholder="密码 6-12位" rangelength="6,12">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">确认密码</label>

                <div class="col-md-9">
                    <input type="password" id="confirmPassword" class="form-control" name="confirmPassword"
                           placeholder="密码 6-12位" rangelength="6,12">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">激活状态</label>

                <div class="col-md-9">
                    <select class="form-control" name="isActive" id="isActive">
                        <option value="0"
                        <#if account.isActive == 0 > selected</#if>
                        > 未激活</option>
                        <option value="1"
                        <#if account.isActive == 1 > selected</#if>
                        >已激活</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label">有效状态</label>

                <div class="col-md-9">
                    <select class="form-control" name="accountStatus" id="accountStatus">
                        <option value="0"
                        <#if account.accountStatus == 0 > selected</#if>
                        >无效</option>
                        <option value="1"
                        <#if account.accountStatus == 1 > selected</#if>
                        >有效</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">
                    <span class="requiredstar">*</span>
                    管辖店铺：
                </label>

                <div class="col-md-5" id="storeNameDiv">
                    <span class="label label-danger f-s-14 m-t-5" style="display: inline-block;"> ${account.storeName}</span>
                    <input type="hidden" name="storeName" value="${account.storeName}"/>
                    <input type="hidden" name="storeId" value="${account.storeId}"/>
                </div>
                <div class="col-md-2">
                    <a id="storeSearch" class="btn btn-success btn-icon btn-circle"
                       onclick="quickSearch('storeName')" title="店铺查询"><i class="fa fa-stack-overflow"></i></a>店铺查询
                </div>
            </div>

            <div class="form-group">
                <label class="col-md-3 control-label">分配角色</label>
                <div class="col-md-9">
                    <@sp.tree actionUrl="${rc.contextPath}/duty/tree" title="分配角色" selected="${selectedDuties}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-3 control-label"></label>
                <div class="col-md-9">
                    <button type="button" id="submitButton" class="btn btn-sm btn-success">提交</button>
                    <button type="button" class="btn btn-sm btn-danger"
                            onclick="getData('${rc.contextPath}/user/query','displayArea')">返回
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="application/javascript">
    $(function () {
        $('#submitButton').click(function () {
            $('#accountForm').submit();
        })
        $('#accountForm').validate({
            rules: {
                isActive: {
                    required: true
                },
                confirmPassword: {
                    equalTo: "#password"
                },
                accountStatus: {
                    required: true
                },
                storeId: {
                    require: true
                }
            },
            messages: {
                accountName: {
                    rangelength: "长度为2-20的字母\\数字\\下划线"
                },
                storeId: {
                    require: "管辖店铺必须选择"
                }
            },
            errorPlacement: function (error, element) {
                error.appendTo(element.parent());
            },
            submitHandler: function () {
                var selectNode = $.selectedTreeNode();
                postDataByFormParams('${rc.contextPath}/user/edit/${account.id}', 'displayArea', 'accountForm', selectNode);
            }
        })
    });

    /**
     * 查询店铺
     * @param name
     */
    function quickSearch(name) {
        alterpage('${rc.contextPath}/backend/store/simple_searchStore/?name='+name, "店铺查询");
    }
</script>